﻿#if UNITY_EDITOR
using System.IO;
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

namespace Core
{
    public class InitEditor
    {
        [MenuItem("Client/Init", priority = 0)]
        public static void InitClient()
        {
            var index = GameConst.CORE_DATA_PATH.LastIndexOf('/');
            var path = GameConst.CORE_DATA_PATH.Substring(0, index);
            var dataPath = $"{Application.dataPath}/Resources/{path}";

            if (!Directory.Exists(dataPath))
                Directory.CreateDirectory(dataPath);

            var dataFullName = $"Assets/Resources/{GameConst.CORE_DATA_PATH}.asset";
            var data = AssetDatabase.LoadAssetAtPath<CoreDataObject>(dataFullName);
            if (data == null)
            {
                var so = ScriptableObject.CreateInstance(typeof(CoreDataObject));
                AssetDatabase.CreateAsset(so, dataFullName);
                data = AssetDatabase.LoadAssetAtPath<CoreDataObject>(dataFullName);
                EditorUtility.SetDirty(so);
                Selection.activeObject = so;
            }

            var excelPath = $"{Application.dataPath}/PackageAssets";
            if (!Directory.Exists(excelPath))
                Directory.CreateDirectory(excelPath);

            var rawExcelPath = $"{Application.dataPath}/Excels";
            if (!Directory.Exists(rawExcelPath))
                Directory.CreateDirectory(rawExcelPath);

            var scriptsPath = $"{Application.dataPath}/Scripts";
            if (!Directory.Exists(scriptsPath))
                Directory.CreateDirectory(scriptsPath);

            AssetDatabase.Refresh();
        }
    }
}
#endif